#pragma once

#ifndef _Collection_h_
#define _Collection_h_

#include <vector>

namespace Framework {

using namespace std;

template<typename T>
class Collection {
public:
    Collection();
    Collection(vector<T> *list);
    virtual ~Collection(void);
    int GetCount();
    void Add(T item);
    void Clear();
    T GetItem(int index);
    int IndexOf(T item);
    bool Remove(T item);
protected:
    virtual void ClearItems();
    virtual void RemoveItem(int index);
private:
    vector<T> items;
};

template<class T>
Collection<T>::Collection() {
}

template<class T>
Collection<T>::~Collection(void) {
}

template<class T>
void Collection<T>::Add(T item) {
    this->items.push_back(item);
}

template<class T>
void Collection<T>::Clear() {
    this->ClearItems();
}

template<class T>
void Collection<T>::ClearItems() {
    this->items.clear();
}

template<class T>
int Collection<T>::GetCount() {
    return this->items.size();
}

template<class T>
T Collection<T>::GetItem(int index) {
    return this->items.at(index);
}

template<class T>
int Collection<T>::IndexOf(T item) {
    for (unsigned int i = 0; i < this->items.size(); i++) {
        if (item == this->items[i]) {
            return i;
        }
    }

    return -1;
}

template<class T>
bool Collection<T>::Remove(T item) {
    int index = this->IndexOf(item);
    if (index < 0) {
        return false;
    }

    this->RemoveItem(index);
    return true;
}

template<class T>
void Collection<T>::RemoveItem(int index) {
    this->items.erase(this->items.begin() + index);
}

}

#endif